local junda = fk.CreateSkill{
  name = "wk_heg__junda",
}

local HG = require "packages.new_heg_diy_my.util"
local H = require "packages.ol_hegemony.util"
local U = require "packages.utility.utility"

Fk:loadTranslationTable{
  ["wk_heg__junda"] = "俊达",
  [":wk_heg__junda"] = "摸牌阶段，你可以改为展示牌堆顶四张牌，然后你获得其中任意张类别各不相同的牌并明置之",
  ["wk_heg__junda_chooseToGet"] = "俊达",
  ["#wk_heg__junda_choose"] = "俊达：请选择类别各不相同的牌",
  ["#wk_heg__junda_show"] = "展示",
}

junda:addEffect(fk.EventPhaseStart, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Draw and
      table.find(player.room:getOtherPlayers(player, false), function(p) return not p:isKongcheng() end)
  end,
  on_use = function(self, event, target, player, data)
    data.phase_end = true
    local room = player.room
    local cards = {}
    local i = 1
    while i < #room.draw_pile and i <= 4 do
      table.insert(cards, room.draw_pile[i])
      i = i + 1
    end
    room:showCards(cards)
    room:delay(800)
    local to_get = room:askToPoxi(player, {
      poxi_type = "wk_heg__junda_chooseToGet",
      data = {{junda.name, cards}},
      cancelable = false,
    })
    room:obtainCard(player, to_get, true, fk.ReasonPrey, player, junda.name)
    room:delay(600)
    HG.showCards(player, to_get)
    return true
  end,
})

Fk:addPoxiMethod{
  name = "wk_heg__junda_chooseToGet",
  card_filter = function (to_select, selected, data, extra_data)
    if not selected or #selected == 0 then return true end
    local types = {}
    table.forEach(selected, function (cid) table.insertIfNeed(types, Fk:getCardById(cid).type) end)
    return not table.contains(types, Fk:getCardById(to_select).type)
  end,
  feasible = function (selected, data, extra_data)
    return #selected > 0
  end,
  prompt = "#wk_heg__junda_choose"
}

return junda
